#!/bin/bash

disk=$1
username=biyouxin
IP=`ifconfig |grep "Bcast"|awk '{print $2}'|awk -F: '{print $2}'|head -1`
##------------Function for format the disk------------##
function fdisk_mkfs()
{
fdisk -S 56 /dev/$disk << EOF
n
p
1
	
	
wq
EOF
sleep 5
mkfs.ext4 /dev/${disk}1
cat >>/etc/fstab <<EOF
`blkid /dev/${disk}1 | awk '{print $2}'|sed 's/\"//g' ` /data  ext4 noatime,nodiratime,acl,defaults 0 0
EOF
mkdir /data
mount -a
}

##------------Function jdk PATH------------##
function jdk_profile()
{
cat >>/etc/profile<<EOF
TMOUT=600
JAVA_HOME=/usr/java/jdk1.7.0_51/
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
PATH=$PATH:$JAVA_HOME/bin
export JAVA_HOME CLASSPATH PATH

EOF
source /etc/profile
}

##------------Function Kernel youhua------------##
function ker_youhua()
{
cat  >>/etc/sysctl.conf << EOF
net.ipv4.tcp_fin_timeout = 30
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.conf.all.accept_redirects=0
EOF
}

##-----------Function the service off------------##
function service_off()
{
chkconfig blk-availability off
chkconfig ip6tables off
chkconfig iptables off
chkconfig iscsi off
chkconfig iscsid off
chkconfig netfs off
chkconfig postfix off
chkconfig udev-post off
chkconfig multipathd off
chkconfig netconsole off
chkconfig rdisc off
chkconfig restorecond off
chkconfig saslauthd off

}

##-------------------------------------------------------------##

if [ ! $# == 1 ];then
	echo "Usage:./${0} \$1  \$2 \$3"
	echo "\$1 You can use command 'fdisk -l' check "
	echo "\$2 is the  server_model for the tomcat"
	echo "\$3 is the  username you should make"
	exit
fi

fdisk_mkfs


#yum install -y pcre-devel openssl-devel gd-devel vixie-cron ntpdate lrzsz

#yum install cronolog -y
#jdk_profile
#chkconfig nginx on


sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
echo "*           soft     nofile    65535 " >> /etc/security/limits.conf
echo "*           hard     nofile    65535 " >> /etc/security/limits.conf
echo "*           soft     nofile    65535 " >> /etc/security/limits.d/90-nproc.conf
echo "*           hard     nofile    65535 " >> /etc/security/limits.d/90-nproc.conf
ker_youhua
service_off
echo "*/30 * * * * /usr/sbin/ntpdate time.nist.gov >/dev/null 2>&1" >>/var/spool/cron/root
#echo "0 3 * * * /bin/bash /data/scripts/checkdisk.sh" >>/var/spool/cron/root
#echo "0 0 * * * /bin/bash /data/scripts/nginx_log_cut.sh" >>/var/spool/cron/root

echo "新建用户"
##------------------------------------##
useradd $username
chown -R ${username}:${username} /data/


sed -i 's/*          soft    nproc     1024/*          soft    nproc     10240/g' /etc/security/limits.d/90-nproc.conf


